home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / src / wangisrc.lha / wangi / z / oldwp / Menu / ProcessMsg.PAS < prev    next >
Pascal/Delphi Source File  |  1995-02-26  |  28KB  |  1,094 lines

  1. Function InitWBMenus : Boolean;
  2.  
  3. Var
  4.     node : pMyNode;
  5.     n2   : pNode;
  6.     ord  : LONG;
  7.     t    : pAppMenuItem;
  8.     
  9. Begin
  10.     WBMport := CreateMsgPort;
  11.     If WBMPort <> NIL Then Begin
  12.         NewList(@wbmlist);
  13.         ord := 0;
  14.         node := pMyNode(currentlist^.lh_Head);
  15.         while node^.wi_Node.ln_Succ <> NIL do begin
  16.             If (node^.wi_Flags and WIF_TOOLMENU)= WIF_TOOLMENU then begin
  17.                 t := AddAppMenuItemA(ord, LONG(node), node^.wi_Node.ln_Name, WBMPort, NIL);
  18.                 If t <> NIL Then Begin
  19.                     n2 := AllocVec(Sizeof(tNode), MEMF_CLEAR);
  20.                     if n2 <> NIL then begin
  21.                         n2^.ln_Name := STRPTR(t);
  22.                         AddTail(@wbmlist, n2);
  23.                     End;
  24.                 End;
  25.             End;
  26.             node := pMyNOde(node^.wi_Node.ln_Succ);
  27.             inc(ord);
  28.         End;
  29.         InitWBMenus := True;
  30.     End;
  31. End;
  32.  
  33. Procedure FreeWBMenus;
  34.  
  35. Var
  36.     node, n2 : pNode;
  37.     Ok : Boolean;
  38.     
  39. Begin
  40.     If WBMPort <> NIL Then Begin
  41.         node := pNode(wbmlist.mlh_Head);
  42.         while node^.ln_Succ <> NIL do begin
  43.             n2 := node^.ln_Succ;
  44.             Ok := RemoveAppMenuItem(pAppMenuItem(node^.ln_Name));
  45.             FreeVec(node);
  46.             node := n2;
  47.         End;
  48.     End;
  49. End;
  50.  
  51. Function InitCx : Boolean;
  52.  
  53. Var
  54.     nb : tNewBroker;
  55.     r  : LONG;
  56.     node : pMyNode;
  57.     hkfilter,
  58.     hksender,
  59.     hktranslate : pCxObj;
  60.     thk : String;
  61.  
  62. Begin
  63.     InitCx := False;
  64.     Cxport := CreateMsgPort;
  65.     if Cxport <> NIL then begin
  66.         { watch this Pascalians ;^). if you put : }
  67.         { With nb do begin                        }
  68.         {   nb_Version := NB_VERSION              }
  69.         { end;                                    }
  70.         { you will not get any messages from Cx   }
  71.         { because you are assigning the field     }
  72.         { nb_Version to the field nb_version and  }
  73.         { not the NB_VERSION constant             }
  74.             
  75.         nb.nb_Version := NB_VERSION;
  76.         With nb do begin
  77.             nb_Name   := @CX_NAME[1];
  78.             nb_Title  := @CX_TITLE[1];
  79.             nb_Descr  := @CX_DESCR[1];
  80.             nb_Unique := 0;
  81.             nb_Flags  := COF_SHOW_HIDE;
  82.             nb_Pri    := V.arg_Pri;
  83.             nb_Port   := CxPort;
  84.             nb_ReservedChannel := 0;
  85.         end;
  86.         Broker := CxBroker(@nb, NIL);
  87.         If broker <> NIL then begin
  88.             V.arg_Hotkey := V.arg_Hotkey + #0;
  89.             Filter := CxFilter(@V.arg_Hotkey[1]);
  90.             if filter <> NIL then begin
  91.                 AttachCxObj(broker,filter);
  92.                 Sender := CxSender(CxPort, -1);
  93.                 If sender <> NIL then begin
  94.                     AttachCxObj(filter, sender);
  95.                     translate := CxTranslate(NIL);
  96.                     if translate <> NIL then begin
  97.                         AttachCxObj(filter, translate);
  98.                         
  99.                         { add all hotkeys }
  100.                         node := pMyNode(currentlist^.lh_Head);
  101.                         while node^.wi_Node.ln_Succ <> NIL do begin
  102.                             thk := PtrToPas(node^.wi_HotKey);
  103.                             If thk <> '' then begin
  104.                                 hkFilter := CxFilter(node^.wi_HotKey);
  105.                                 if hkfilter <> NIL then begin
  106.                                     AttachCxObj(broker,hkfilter);
  107.                                     hksender := CxSender(CxPort, LONG(node));
  108.                                     If hksender <> NIL then begin
  109.                                         AttachCxObj(hkfilter, hksender);
  110.                                         hktranslate := CxTranslate(NIL);
  111.                                         if hktranslate <> NIL then begin
  112.                                             AttachCxObj(hkfilter, hktranslate);
  113.                                         End;
  114.                                     End;
  115.                                 End;
  116.                             End;
  117.                             node := pMyNode(node^.wi_Node.ln_Succ);
  118.                         end;                        
  119.                         
  120.                         if (CxObjError(filter) = 0) then begin
  121.                             r := ActivateCxObj(broker, 1);
  122.                             InitCx := True;
  123.                         End;
  124.                     End;
  125.                 End;
  126.             End;
  127.         End;
  128.     End;
  129. End;
  130.  
  131. Procedure RemoveCx;
  132.  
  133. Var
  134.     msg : pMessage;
  135.     
  136. Begin
  137.     DeleteCxObjAll(broker);
  138.     { clear the port of any last minute messages }
  139.     Msg := GetMsg(Cxport);
  140.     While msg <> NIL do begin
  141.         ReplyMsg(msg);
  142.         Msg := GetMsg(Cxport);
  143.     end;
  144.     { remove the port }
  145.     DeleteMsgPort(CxPort);
  146. end;
  147.  
  148. { Set up Port for IPC messages from WangiPrefs }
  149. Function InitIPC : Boolean;
  150.  
  151. Begin
  152.     InitIPC := False;
  153.     WangiPort := CreateMsgPort;
  154.     If WangiPort <> NIL then begin
  155.         wangiport^.mp_Node.ln_Name := CStrConstPtrAR(@grk, 'WangiPad_Port');
  156.         wangiport^.mp_Node.ln_Pri := 0;
  157.         AddPort(WangiPort);
  158.         InitIPC := True;
  159.     End;
  160. End;
  161.  
  162. { remove IPC port }
  163. Procedure RemoveIPC;
  164.  
  165. Var
  166.     Ok : Boolean;
  167.     m  : pMessage;
  168.     
  169. Begin
  170.     if WangiPort <> NIL then begin
  171.         m := GetMsg(WangiPort);
  172.         While m <> NIL do begin
  173.             ReplyMsg(m);
  174.             m := GetMsg(WangiPort);
  175.         End;
  176.     End;
  177.     if WangiPort <> NIL then begin
  178.         RemPort(WangiPort);
  179.         DeleteMsgPort(WangiPort);
  180.     End;
  181.     WangiPort := NIL;
  182. End;
  183.  
  184. { Set up Port for notify messages from DOS }
  185. Function InitNotify : Boolean;
  186.  
  187. Var
  188.     ok : Boolean;
  189.  
  190. Begin
  191.     InitNotify := False;
  192.     NotifyPort := CreateMsgPort;
  193.     If NotifyPort <> NIL then begin
  194.         nr := AllocVec(Sizeof(tNotifyRequest), MEMF_CLEAR);
  195.         if nr <> NIL then begin
  196.             With nr^ do begin
  197.                 nr_Name        := CStrConstPtrAR(@grk, V.arg_From);
  198.                 nr_UserData    := 337;
  199.                 nr_Flags       := NRF_SEND_MESSAGE;
  200.                 nr_Msg.nr_Port := NotifyPort;
  201.             End;
  202.             Ok := StartNotify(nr);
  203.             InitNotify := True;
  204.         End;
  205.     End;
  206. End;
  207.  
  208. Procedure RemoveNotify;
  209.  
  210. Begin
  211.     If notifyPort <> NIL then begin
  212.         EndNotify(nr);
  213.         DeleteMsgPort(NotifyPort);
  214.         FreeVec(nr);
  215.     End;
  216. End;
  217.  
  218.  
  219. Function InitTimer : Boolean;
  220.  
  221. Begin
  222.     Inittimer := false;
  223.     TimerPort := CreateMsgPort;
  224.     If timerport <> NIL then begin
  225.         tio := pTimeRequest(CreateIORequest(TimerPort, sizeof(ttimerequest)));
  226.         if tio <> NIL then begin
  227.             If OpenDevice(TIMERNAME,UNIT_VBLANK, pIORequest(tio),0) = 0 then
  228.                 InitTimer := True;
  229.         End;
  230.     End;
  231. End;
  232.  
  233. Procedure CloseTimer;
  234.  
  235. Var
  236.     e : LONG;
  237.     
  238. begin
  239.     If tio <> NIL then begin
  240.         If CheckIO(pIORequest(tio)) = NIL then begin
  241.             AbortIO(pIORequest(tio));
  242.             e := WaitIO(pIORequest(tio));
  243.         End;
  244.         CloseDevice(pIORequest(tio));
  245.         DeleteIORequest(pIORequest(tio));
  246.     End;
  247.     DeleteMsgPort(TimerPort);
  248. End;
  249.  
  250. Procedure SendTimer;
  251.  
  252. Begin
  253.     If (CD.cd_Level = LEV_FRONT) or (CD.cd_Level = LEV_BACKM) then begin
  254.         tio^.tr_Node.io_Command := TR_ADDREQUEST;
  255.         tio^.tr_Node.io_Flags := 0;
  256.         tio^.tr_Node.io_Error := 0;
  257.         tio^.tr_Time.tv_Secs := V.arg_LevelT;
  258.         tio^.tr_Time.tv_Micro := 0; 
  259.         SendIO(pIORequest(tio));
  260.     End
  261. End;
  262.  
  263.  
  264.  
  265.  
  266. Procedure HandleResize(w : pWindow);
  267.     
  268. Var
  269.     pos, Top : LONG;
  270.     t : Array[0..3] of tTagItem;
  271.     
  272. Begin
  273.     pos := RemoveGList(w, g[G_NI], -1);
  274.     if pos <> -1 then begin
  275.         EraseRect(w^.RPort, 0, 0, w^.Width, w^.Height);
  276.         CD.cd_LeftEdge := w^.LeftEdge;
  277.         CD.cd_TopEdge := w^.TopEdge;
  278.         CD.cd_Width := w^.Width;
  279.         CD.cd_Height := w^.Height;
  280.         
  281.         pos := 0;
  282.         if GadToolsBase^.lib_Version >= 39 then begin
  283.             T[0].ti_Tag  := GTLV_Top;
  284.             T[0].ti_Data := LONG(@Top);
  285.             T[1].ti_Tag  := TAG_END;
  286.             pos := GT_GetGadgetAttrsA(g[G_LV], w, NIL, @t);
  287.         End;
  288.         if pos = 0 then top := 0;
  289.         
  290.         FreeGadgets(g[G_NI]);
  291.         g[G_NI] := NIL;
  292.         G[G_CC] := CreateContext(@G[G_NI]);
  293.         If G[G_CC] <> NIL Then begin
  294.             G[G_LV] := MakeLVGadget(G[G_CC]);
  295.             
  296.             pos := AddGList(w, g[G_NI], $FFFF, -1, NIL);
  297.             RefreshGList(g[G_NI], w, NIL, -1);
  298.             GT_RefreshWindow(w,NIL);
  299.             RefreshWindowFrame(w);
  300.         End;
  301.     End;
  302. End;
  303.  
  304.  
  305. Procedure EnableWindow(w : pWindow; key : Pointer);
  306.  
  307. Var
  308.     edw : pEnDisWin;
  309.  
  310. Begin
  311.     if pLibrary(SysBase)^.lib_Version >= 39 then begin
  312.         SetWindowPointerA(w, NIL);
  313.         edw := pEnDisWin(key);
  314.         If edw <> NIL then begin
  315.             if edw^.edw_Req <> NIL then begin
  316.                 EndRequest(edw^.edw_Req, w);
  317.                 if (edw^.edw_OldWidth <> w^.Width) or 
  318.                    (edw^.edw_OldHeight <> w^.Height) then { resize window }
  319.                     HandleResize(w);
  320.                 FreeVec(edw^.edw_Req);
  321.                 FreeVec(edw);
  322.             End;
  323.         End;
  324.     End else begin
  325.         if ReqToolsBase <> NIL then begin
  326.             if key <> NIL then begin
  327.                 rtUnLockWindow(w, Key);
  328.             End;
  329.         End;
  330.     End;
  331. End;
  332.  
  333. Function DisableWindow(w : pWindow) : Pointer;
  334.  
  335. Var
  336.     t : Array[0..4] of LONG;
  337.     req : pEnDisWin;
  338.  
  339. begin
  340.     DisableWindow := NIL;
  341.     if pLibrary(SysBase)^.lib_Version >= 39 then begin
  342.         t[0] := WA_BusyPointer;
  343.         t[1] := True_;
  344.         t[2] := WA_PointerDelay;
  345.         t[3] := True_;
  346.         t[4] := TAG_END;
  347.         SetWindowPointerA(w, @t);
  348.         req := AllocVec(sizeof(tEnDisWin), MEMF_CLEAR);
  349.         if req <> NIL then begin
  350.             req^.edw_Req := AllocVec(sizeof(tRequester), MEMF_CLEAR);
  351.             if req^.edw_req <> NIL then begin
  352.                 If Request(req^.edw_req, w) then begin
  353.                     req^.edw_OldWidth := w^.Width;
  354.                     req^.edw_OldHeight := w^.Height;
  355.                     DisableWindow := Pointer(req);
  356.                 end else begin
  357.                     FreeVec(req^.edw_Req);
  358.                     FreeVec(req);
  359.                 End;
  360.             End;
  361.         End;
  362.     End else begin
  363.         If ReqtoolsBase <> NIL then
  364.             DisableWindow := Pointer(rtLockWindow(w));
  365.     End;
  366. end;
  367.  
  368. Function PutArgs(cmd : String; am : pAppMessage) : String;
  369.  
  370. Var
  371.     FirstPart, 
  372.     SecondPart,
  373.     ts        : String;
  374.     n, place  : Integer;
  375.     buf       : STRPTR;
  376.     wbarg     : pWBArg;
  377.     
  378. Begin
  379.     place := 0;
  380.     For n := 1 to length(cmd)-1 do begin
  381.         if cmd[n] = '[' then begin
  382.             if cmd[n+1] = ']' then begin 
  383.                 place := n;
  384.             End;
  385.         End;
  386.     End; 
  387.     If place > 0 then begin
  388.         FirstPart := Copy(cmd, 1, place-1);
  389.         Secondpart := Copy(cmd, place+2, Length(cmd)-place-1)+#0;
  390.         If am <> NIL then begin
  391.             wbarg := am^.am_ArgList;
  392.             For n := 1 to am^.am_NumArgs do begin
  393.                 buf := AllocVec(255, MEMF_CLEAR);
  394.                 if buf <> NIL Then begin
  395.                     If wbarg^.wa_Lock <> NULL then begin
  396.                         If NameFromLock(wbarg^.wa_Lock, buf, 255) then begin
  397.                             If AddPart(buf, STRPTR(WBArg^.wa_Name), 255) then begin
  398.                                 ts := PtrToPas(buf);
  399.                                 If pos(' ', ts) <> 0 then
  400.                                     ts := '"' + ts + '"';
  401.                                 ts := ts + ' ';
  402.                                 if Length(firstpart)+length(ts)+length(secondpart) < 256 then
  403.                                 Firstpart := Firstpart + ts;
  404.                             End;
  405.                         End;
  406.                     End;
  407.                     FreeVec(buf);
  408.                 End;
  409.                 wbarg := pWBArg(LONG(wbarg)+Sizeof(tWBArg));
  410.             End;
  411.         End;
  412.         FirstPArt := FirstPart + SecondPart + #0;
  413.     End else
  414.         FirstPart := cmd+#0;
  415.     PutArgs := FirstPart;
  416. End;
  417.  
  418.  
  419.  
  420. Function  StartCLIProgram(node : pMyNode; am : pAppMessage) : Boolean;
  421.     
  422. VAR
  423.     newcd, cd,
  424.     oldcd   : BPTR;
  425.     t       : Array[0..14] of LONG;
  426.     out,
  427.     expcmd  : String;
  428.     outfile : BPTR;
  429.     rc,OK   : Boolean;
  430.     pl      : pPathList;
  431.  
  432. Begin
  433.     { Send the ARexx command }
  434.     SendARexxCommand(PtrToPas(node^.wi_RexxCmd),PtrToPas(node^.wi_RexxPort),am);
  435.     rc := False;
  436.     newcd := Lock(node^.wi_Cmd[0] ,SHARED_LOCK);
  437.     if (newcd <> 0) and (PtrToPas(node^.wi_Cmd[1]) <> '') then begin
  438.     
  439.         { subsitute args }
  440.         expcmd := PutArgs(PtrToPas(node^.wi_Cmd[1]),am);
  441.         
  442.         { if wished, allow user to alter cmd line }
  443.         If ((node^.wi_Flags and WIF_EDITCMD) = WIF_EDITCMD) and (ReqToolsBase <> NIL) Then Begin
  444.             t[0] := RTGS_GadFmt;
  445.             t[1] := LONG(CStrConstPtrAR(@prk, 'Ok'));
  446.             t[2] := TAG_END;
  447.             t[0] := rtGetStringA(@expcmd[1], 255, 
  448.                                CStrConstPtrAR(@prk, 'Edit Command Line'), NIL, @t); 
  449.         End;
  450.                             
  451.         { Go to program's current directory }
  452.         oldcd := CurrentDir(newcd);
  453.             
  454.         { open IO file }
  455.         Out :=  PtrToPas(node^.wi_Output);
  456.         If Out = '' then
  457.             Out := 'NIL:'#0
  458.         else 
  459.             out := out+#0;
  460.         
  461.         outfile := Open(@out[1], MODE_OLDFILE);
  462.             
  463.         { Copy path list }
  464.         If gp <> NIL then
  465.             CopyPathList(gp, pl)
  466.         else
  467.             pl := NIL;
  468.             
  469.         { Start program }    
  470.         t[ 0] := SYS_Asynch;
  471.         t[ 1] := True_;
  472.         t[ 2] := SYS_Input;
  473.         t[ 3] := outfile;
  474.         t[ 4] := SYS_Output;
  475.         t[ 5] := 0;
  476.         t[ 6] := NP_StackSize;
  477.         t[ 7] := node^.wi_Stack;
  478.         t[ 8] := NP_Priority;
  479.         t[ 9] := node^.wi_Priority;
  480.         t[10] := SYS_UserShell;
  481.         t[11] := True_;
  482.         if pl <> NIL then begin
  483.             t[12] := NP_Path;
  484.             t[13] := MKBADDR(pl);
  485.         end else
  486.             t[12] := TAG_END;
  487.         t[14] := TAG_END;
  488.         if SystemTagList(@expcmd[1],@t) = 0 then
  489.             rc := TRUE { Program started! } 
  490.         else begin
  491.             { failed, free alloc'ed resources }
  492.             OK := Close_(outfile);
  493.             FreePathList(pl);
  494.         End;
  495.                 
  496.         { Go back to old current directory }
  497.         newcd := CurrentDir(oldcd);
  498.     End;
  499.     UnLock(newcd);
  500.     if PtrToPas(node^.wi_Cmd[1]) = '' then 
  501.         rc := True;
  502.     StartCLIProgram := rc;
  503. End;
  504.  
  505. { Start WB program }
  506. Function StartWBProgram(node : pMyNode; msg : pAppMessage) : Boolean;
  507.  
  508. Var
  509.     hp        : pMsgPort; { port of handler }
  510.     wbsm      : tWBStartMsg; { message for handler }
  511.     rc        : Boolean;
  512.     dummyport : pMsgPort;
  513.     m         : pMessage;
  514.     i         : LONG;
  515.     t         : Array[0..14] of LONG;
  516.     pl        : pPathList;
  517.         
  518. Begin
  519.     { Send the ARexx command }
  520.     SendARexxCommand(PtrToPas(node^.wi_RexxCmd),PtrToPas(node^.wi_RexxPort),msg);
  521.     
  522.     rc := False;
  523.     
  524.     DummyPort := CreateMsgPort;
  525.     If DummyPort <> NIL then begin
  526.     
  527.         { Build message for WBStart-Handler }
  528.         wbsm.wbsm_Msg.mn_Node.ln_Pri:= 0;
  529.         wbsm.wbsm_Msg.mn_ReplyPort  := DummyPort;
  530.         wbsm.wbsm_Name              := node^.wi_Cmd[1];
  531.         wbsm.wbsm_DirLock           := Lock(node^.wi_Cmd[0],SHARED_LOCK);
  532.         wbsm.wbsm_Stack             := node^.wi_Stack;
  533.         wbsm.wbsm_Prio              := node^.wi_Priority;
  534.         if msg <> NIL then begin
  535.             wbsm.wbsm_NumArgs         := msg^.am_NumArgs;
  536.             wbsm.wbsm_ArgList         := msg^.am_ArgList;
  537.         End else begin
  538.             wbsm.wbsm_NumArgs         := 0;
  539.             wbsm.wbsm_ArgList         := NIL;
  540.         End;
  541.  
  542.         { Try to send a message to the WBStart-Handler }
  543.         Forbid;
  544.         hp := FindPort(@WBS_PORTNAME[1]);
  545.         If hp <> NIL then
  546.             PutMsg(hp, pMessage(@wbsm));
  547.         Permit;
  548.  
  549.         { No WBStart-Handler, try to start it! }
  550.         If hp = NIL then begin
  551.         
  552.             { Copy path list }
  553.             If gp <> NIL then
  554.                 CopyPathList(gp, pl)
  555.             else
  556.                 pl := NIL;
  557.             
  558.             { Start handler }
  559.             t[ 0] := SYS_Input;
  560.             t[ 1] := 0;
  561.             t[ 2] := SYS_Output;
  562.             t[ 3] := 0;
  563.             t[ 4] := SYS_Asynch;
  564.             t[ 5] := True_;
  565.             t[ 6] := SYS_UserShell;
  566.             t[ 7] := True_;
  567.             t[ 8] := NP_ConsoleTask;
  568.             t[ 9] := 0;
  569.             t[10] := NP_WindowPtr;
  570.             t[11] := 0;
  571.             if pl <> NIL then begin
  572.                 t[12] := NP_Path;
  573.                 t[13] := MKBADDR(pl);
  574.                 t[14] := TAG_DONE;
  575.             end else
  576.                 t[12] := TAG_DONE;
  577.             If SystemTagList(@WBS_LOADNAME[1], @t) <> - 1 then begin
  578.                 { Handler started, try to send message (Retry up to 5 seconds) }
  579.                 Ok := True;
  580.                 i := 0;
  581.                 While (i<10) and OK do begin
  582.                     { Try to send message }
  583.                     Forbid;
  584.                     hp := FindPort(@WBS_PORTNAME[1]);
  585.                     if hp <> NIL then
  586.                         PutMsg(hp, pMessage(@wbsm));
  587.                     Permit;
  588.                     
  589.                     { Message sent? Yes, leave loop }
  590.                     If hp <> NIL then 
  591.                         OK := False
  592.                     else 
  593.                         { No, wait 1/2 second }
  594.                         Delay(25);
  595.                     i := i + 1;
  596.                 End;
  597.             End;
  598.         End;
  599.     
  600.         { Could we send the message? }
  601.         if (hp <> NIL) then Begin
  602.             { Get reply message }
  603.             m := WaitPort(DummyPort);
  604.             m := GetMsg(DummyPort);
  605.             rc := Boolean(wbsm.wbsm_Stack); { Has tool been started? }
  606.         End;
  607.         { Free lock }
  608.         if (wbsm.wbsm_DirLock <> NULL) then
  609.             UnLock(wbsm.wbsm_DirLock);
  610.         { close port }
  611.         DeleteMsgPort(dummyport);
  612.     End;
  613.     StartWBProgram := rc;
  614. End;
  615.  
  616.  
  617.  
  618. Procedure HandleGadget(w : pWindow; gadcode : pGadget; num : LONG);
  619.  
  620. Var
  621.     node : pMyNode;
  622.     n    : Integer;
  623.     selected : Boolean;
  624.     
  625. Begin       
  626.     Case gadcode^.GadgetID Of 
  627.         G_LV  : begin
  628.             { flag that the currenttop is nolonger 0 }
  629.             if num > (LVRows-1) then 
  630.                 currenttop := -1
  631.             else
  632.                 currenttop := 0;
  633.                 
  634.             selected := False;
  635.             If CD.cd_Selection = SEL_DOUBLE then begin
  636.                 if num = oldLVord then begin
  637.                     If DoubleClick(oldsecs, oldmics, secs, mics) then
  638.                         { double click }
  639.                         selected := True;
  640.                 end else
  641.                     oldlvord := num;
  642.             end else
  643.                 selected := true;
  644.                 
  645.             If selected then begin
  646.                 node := pMyNode(currentlist^.lh_Head);
  647.                 For n := 1 to num do begin
  648.                     node := pMyNode(node^.wi_Node.ln_Succ);
  649.                 End;
  650.                 
  651.                 Case node^.wi_Type of
  652.                     TYPE_SHELL : If NOT StartCLIProgram(node, NIL) then
  653.                         TellError(ERROR_SHELL);
  654.                     TYPE_WB : If NOT StartWBProgram(node, NIL) then
  655.                         TellError(ERROR_WB);
  656.                     TYPE_AREXX : SendARexxCommand(PtrToPas(node^.wi_RexxCmd),
  657.                                                   PtrToPas(node^.wi_RexxPort),NIL); 
  658.                 End;
  659.             End;
  660.         End;
  661.     End;
  662.     oldsecs := secs;
  663.     oldmics := mics;
  664. End;
  665.  
  666.  
  667. Procedure RefreshTheWindow(VAR w : pWindow);
  668.  
  669. begin
  670.     GT_BeginRefresh(w);
  671.     GT_EndRefresh(w, True);
  672. end;
  673.  
  674. Procedure OpenUpWindow(Var w : pWindow; VAR mask, AppMask : LONG);
  675.  
  676. Begin
  677.     if w = NIL then begin
  678.         opened := False;    
  679.         w := OpenTheWindow;
  680.         Mask := BitMask(w^.UserPort^.MP_SIGBIT);
  681.         InitMenus(w);
  682.         If AddAppWin(w) Then
  683.             AppMask := BitMask(AppPort^.MP_SIGBIT);
  684.         opened := True;
  685.     End;
  686. End;
  687.  
  688. Procedure HideWindow(Var w : pWindow; VAR mask, AppMask : LONG);
  689.  
  690. Begin
  691.     If w <> NIL then begin
  692.         opened := True;
  693.         { save position so the if WangiPrefs asks for we can give it }
  694.         hidenpos[1] := w^.LeftEdge;
  695.         hidenpos[2] := w^.TopEdge;
  696.         hidenpos[3] := w^.Width;
  697.         hidenpos[4] := w^.height;
  698.         FreeMenus(w);
  699.         RemoveAppWin;
  700.         CloseTheWindow(w);
  701.         w := NIL;
  702.         mask := 0;
  703.         AppMask := 0;
  704.         opened := False;
  705.     End;
  706. End;
  707.  
  708.  
  709. Procedure ProcessWindowEvents(Var w : pWindow);
  710.  
  711. CONST
  712.     Exitflag : Boolean = False;
  713.     
  714. VAR 
  715.     port               : pMsgPort;
  716.     IDCMPMsg           : pIntuiMessage;
  717.     CxMsg              : pCxMsg;
  718.     ipcmsg             : pIPCMsg;
  719.     am                 : pAppMessage;
  720.     notifymsg          : pNotifyMessage;
  721.     msg                : pMessage;
  722.     MsgClass, sigre,
  723.     WinMask, CxMask,
  724.     WangiMask, AppMask,
  725.     NotifyMask, TimerMask,
  726.     WBMMask, cxtype, prev,
  727.     ipctype, LVY, ordn,
  728.     tmp, tmp2, 
  729.     menunumber, y      : LONG;
  730.     MsgCode            : Word;
  731.     Gadcode            : pGadget;
  732.     ez                 : pEasyStruct;
  733.     t                  : Array[0..6] of LONG;
  734.     nde                : pNode;
  735.     ts                 : String;
  736.     item               : pMenuItem;
  737.     hide               : Boolean;
  738.     mn                 : pMyNode;
  739.     Key                : Pointer;
  740.     al                 : Array[0..2] of LONG;
  741.     CxID, mnode        : pMyNode;
  742.  
  743. begin
  744.     SendTimer;
  745.     currenttop := 0;
  746.     CxMask     := BitMask(CxPort^.MP_SIGBIT);      { for CX msgs                 }
  747.     WangiMask  := BitMask(WangiPort^.MP_SIGBIT);   { for msgs to/from WangiPrefs }
  748.     WinMask    := BitMask(w^.UserPort^.MP_SIGBIT); { for IDCMP msgs              }
  749.     AppMask    := BitMask(AppPort^.MP_SIGBIT);     { for appwindow msgs          }
  750.     NotifyMask := BitMask(NotifyPort^.MP_SIGBIT);  { for DOS Notify msgs         }
  751.     TimerMask  := BitMask(TimerPort^.MP_SIGBIT);   { for Timer device prods      }
  752.     WBMMask    := BitMask(WBMPort^.MP_SIGBIT);     { for AppMenuItems            } 
  753.  
  754.     
  755.     While Not exitflag Do Begin
  756.         sigre := Wait(WinMask|AppMask|WangiMask|CxMask|WBMMask|
  757.                       NotifyMask|TimerMask|SIGBREAKF_CTRL_C);
  758.         
  759.         if ((sigre and SIGBREAKF_CTRL_C)=SIGBREAKF_CTRL_C) then
  760.             ExitFlag := True;
  761.         
  762.         if ((sigre and TimerMask)=TimerMask) then begin
  763.             Msg := GetMsg(TimerPort);
  764.             While Msg <> NIL do begin
  765.                 If opened then begin
  766.                     If CD.cd_Level = LEV_BACKM then
  767.                         WindowToback(w);
  768.                     If CD.cd_Level = LEV_FRONT then
  769.                         WindowToFront(w);
  770.                 End;
  771.                 Msg := GetMsg(TimerPort);
  772.             End;
  773.             SendTimer;
  774.         End;
  775.         
  776.         if ((sigre and WBMMask)=WBMMask) then begin
  777.             am := pAppMessage(GetMsg(WBMPort));
  778.             while am <> NIL do begin
  779.                 mnode := pMyNode(am^.am_UserData);
  780.                 If mnode <> NIL then begin
  781.                     Case mnode^.wi_Type of
  782.                         TYPE_SHELL : If NOT StartCLIProgram(mnode, am) then
  783.                             TellError(ERROR_SHELL);
  784.                         TYPE_WB : If NOT StartWBProgram(mnode, am) then
  785.                             TellError(ERROR_WB);
  786.                         TYPE_AREXX : SendARexxCommand(PtrToPas(mnode^.wi_RexxCmd),
  787.                                                     PtrToPas(mnode^.wi_RexxPort),am); 
  788.                     End;
  789.                 End;
  790.                 ReplyMsg(pMessage(am));
  791.                 am := pAppMessage(GetMsg(WBMPort));
  792.             End;
  793.         End;
  794.         
  795.         if ((sigre and WinMask)=WinMask) and (winmask <> 0) then begin
  796.             hide := false;
  797.             IDCMPMsg  := GT_GetIMsg(w^.userPort);
  798.             while IDCMPMsg <> NIL do begin
  799.                 MsgClass := IDCMPMsg^.Class;
  800.                 MsgCode  := IDCMPMsg^.Code;
  801.                 GadCode  := pGadget(IDCMPMsg^.IAddress);
  802.                 secs     := IDCMPMsg^.Seconds;
  803.                 mics     := IDCMPMsg^.Micros;    
  804.                 GT_ReplyIMsg(IDCMPMsg);
  805.                 Case MsgClass Of
  806.                     IDCMP_CLOSEWINDOW   : begin
  807.                         Hide := True;
  808.                     End;
  809.                     IDCMP_REFRESHWINDOW : RefreshTheWindow(w);        
  810.                     IDCMP_GADGETUP      : HandleGadget(w, gadcode, msgcode);
  811.                     IDCMP_NEWSIZE       : HandleResize(w);
  812.                     IDCMP_VANILLAKEY    : Case MsgCode of
  813.                         27  { ESC    },
  814.                         81  { Q      },
  815.                         113 { q      },
  816.                         3   { Ctrl-C } : ExitFlag := True;
  817.                         72  { H      },
  818.                         104 { h      } : Hide := True;
  819.                         Else DisplayBeep(NIL);
  820.                     End;
  821.                     IDCMP_MENUPICK : Begin
  822.                         menunumber := msgcode;
  823.                         While (menunumber <> MENUNULL) do begin
  824.                             item := ItemAddress(menustrip, menunumber);
  825.                             Case LONG(GTMENUITEM_USERDATA(item)) of
  826.                                 M_PREF : Begin
  827.                                     mn := AllocVec(Sizeof(tMyNode), MEMF_CLEAR);
  828.                                     if mn <> NIL then begin
  829.                                         With mn^ do begin
  830.                                             wi_Cmd[0]   := CStrConstPtrAR(@prk, '');
  831.                                             wi_Cmd[1]   := CStrConstPtrAR(@prk, V.arg_PrefEd+' '+V.arg_From);
  832.                                             wi_RexxPort := CStrConstPtrAR(@prk, '');
  833.                                             wi_RexxCmd  := CStrConstPtrAR(@prk, '');
  834.                                             wi_OutPut   := CStrConstPtrAR(@prk, 'NIL:'); 
  835.                                         End;
  836.                                         If NOT StartCLIProgram(mn, NIL) then
  837.                                             TellError(ERROR_LOSTPREFS);
  838.                                         FreeVec(mn);
  839.                                     End;
  840.                                 End; 
  841.                                 M_ABOUT : Begin
  842.                                     key := DisableWindow(w);
  843.                                     ez := AllocVec(Sizeof(tEasyStruct), MEMF_CLEAR);
  844.                                     if ez <> NIL then begin
  845.                                         With ez^ do begin
  846.                                             es_StructSize :=  Sizeof(tEasyStruct);
  847.                                             es_Title := CStrConstPtrAR(@prk, 'WangiPad Information');
  848.                                             es_TextFormat := CStrConstPtrAR(@prk, 
  849.                                                 'WangiPad Copyright ©Lee Kindness.'#10+
  850.                                                 '%s'#10#10+
  851.                                                 'The easiest way to launch your programs.'#10+
  852.                                                 'Read "WangiPad.Guide" for more information'#10#10+
  853.                                                 'Comments to:'#10+
  854.                                                 ' Lee Kindness'#10+
  855.                                                 ' 8 Craigmarn Road'#10+
  856.                                                 ' Portlethen Village'#10+
  857.                                                 ' Aberdeen AB1 4QR'#10+
  858.                                                 ' SCOTLAND'#10#10+
  859.                                                 'Registered to: %s'#10+
  860.                                                 'ID: %lx');
  861.                                             es_GadgetFormat := CStrConstPtrAR(@prk, 'Ok');
  862.                                         End;
  863.                                         al[0] := LONG(@WVer[6]);
  864.                                         al[1] := LONG(CStrConstPtrAR(@prk, Reg.key_User));
  865.                                         al[2] := Reg.key_ID;
  866.                                         y := EasyRequestArgs(w, ez, NIL, @al);
  867.                                         FreeVec(ez);
  868.                                     end;
  869.                                     EnableWindow(w, key);
  870.                                 end;
  871.                                 M_HIDE : hide := true;
  872.                                 M_QUIT : ExitFlag := True;
  873.                             End;
  874.                             menunumber := item^.NextSelect;
  875.                         end;    
  876.                     End;
  877.                 End;
  878.                 if NOT Hide then
  879.                     IDCMPMsg  := GT_GetIMsg(w^.userPort)
  880.                 else begin
  881.                     IDCMPMsg  := GT_GetIMsg(w^.userPort);
  882.                     While IDCMPMsg <> NIL do begin
  883.                         { remove all messages }
  884.                         GT_ReplyIMsg(IDCMPMsg);
  885.                         IDCMPMsg  := GT_GetIMsg(w^.userPort);
  886.                     End;
  887.                     { close/hide window }
  888.                     HideWindow(w, winmask, appmask);
  889.                 End;
  890.             End;
  891.         End; {WinMask}
  892.         
  893.         if ((sigre and AppMask)=appMask) and (appmask <> 0) then begin
  894.             am := pAppMessage(GetMsg(AppPort));
  895.             while am <> NIL do begin
  896.                 LVY := am^.am_MouseY;
  897.                 If LVY > G[G_LV]^.TopEdge+2 then begin
  898.                     LVY := LVY-G[G_LV]^.TopEdge+2; { pixels below LV }
  899.                     If LVY < CD.cd_Font.ta_YSize then
  900.                         LVY := CD.cd_Font.ta_YSize;
  901.                     LVY := (Round(LVY / CD.cd_Font.ta_YSize))-1; { ordinal value of item }
  902.                     If LVY <= LVRows then begin
  903.                     
  904.                         { count num of nodes }
  905.                         ordn := -1;
  906.                         nde := currentlist^.lh_Head;
  907.                         while nde^.ln_Succ <> NIL do begin
  908.                             ordn := ordn + 1;
  909.                             nde := nde^.ln_Succ;
  910.                         end;
  911.                         If LVY > Ordn then
  912.                             LVY := Ordn;
  913.                         
  914.                         { If GadTools > 39 then get the current top }
  915.                         If GadToolsBase^.lib_Version >=39 then begin
  916.                             t[0] := GTLV_TOP;
  917.                             t[1] := LONG(@currenttop);
  918.                             t[2] := TAG_END;
  919.                             tmp2 := GT_GetGadgetAttrsA(G[G_LV], w, NIL, @t);
  920.                             if currenttop <> -1 then begin
  921.                                 LVY := LVY + currenttop;
  922.                                 If LVY > Ordn then
  923.                                     LVY := Ordn;
  924.                             End;
  925.                         End;
  926.                             
  927.                         If currenttop <> -1 then begin
  928.                             { Get appropriate node }
  929.                             nde := currentlist^.lh_Head;
  930.                             For ordn := 1 to LVY do
  931.                                 nde := nde^.ln_Succ;
  932.                             
  933.                             { Highlight node }
  934.                             t[0] := GTLV_Selected;
  935.                             t[1] := LVY;
  936.                             t[2] := TAG_END;
  937.                             GT_SetGadgetAttrsA(G[G_LV], w, NIL, @t);
  938.                         
  939.                             Case pMyNode(nde)^.wi_Type of
  940.                                 TYPE_SHELL : If NOT StartCLIProgram(pMyNode(nde), am) then
  941.                                     TellError(ERROR_SHELL);
  942.                                 TYPE_WB : If NOT StartWBProgram(pMyNode(nde), am) then
  943.                                     TellError(ERROR_WB);
  944.                                 TYPE_AREXX : SendARexxCommand(PtrToPas(pMyNode(nde)^.wi_RexxCmd),
  945.                                                           PtrToPas(pMyNode(nde)^.wi_RexxPort),am); 
  946.                             End;
  947.                         End else
  948.                             { with WB 2 we cant work out the current top... }
  949.                             TellError(ERROR_NOTWB2);
  950.                                 
  951.                     End;
  952.                 End;
  953.                 
  954.                 ReplyMsg(pMessage(am));
  955.                 am := pAppMessage(GetMsg(AppPort));
  956.             End;
  957.         End;
  958.         
  959.         if ((sigre and WangiMask)=WangiMask) then begin
  960.             ipcmsg := pIPCMsg(GetMsg(WangiPort));
  961.             While IPCMsg <> NIL do begin
  962.                 ipctype := ipcmsg^.ipc_Type;
  963.                 ReplyMsg(pMessage(ipcmsg));
  964.                 { wangi prefs wants us to free msg mem }
  965.                 FreeVec(ipcmsg);
  966.                 
  967.                 Case ipctype of 
  968.                     IPC_REQUESTSIZES : begin
  969.                         { WangiPrefs wants current dims. of the window }
  970.                         ipcmsg := AllocVec(sizeof(tIPCMsg), MEMF_CLEAR);
  971.                         if ipcmsg <> NIL then begin
  972.                             ipcmsg^.ipc_Msg.mn_Length := sizeof(tIPCMsg);
  973.                             If opened then begin
  974.                                 ipcmsg^.ipc_Left   := w^.LeftEdge;
  975.                                 ipcmsg^.ipc_Top    := w^.TopEdge;
  976.                                 ipcmsg^.ipc_Width  := w^.Width;
  977.                                 ipcmsg^.ipc_Height := w^.height;
  978.                             End else begin
  979.                                 ipcmsg^.ipc_Left   :=hidenpos[1]; 
  980.                                 ipcmsg^.ipc_Top    :=hidenpos[2]; 
  981.                                 ipcmsg^.ipc_Width  :=hidenpos[3]; 
  982.                                 ipcmsg^.ipc_Height :=hidenpos[4];
  983.                             End;
  984.                         
  985.                             ipcmsg^.ipc_Type := IPC_SENDSIZES;
  986.                             
  987.                             Forbid;
  988.                             Port := FindPort(CStrConstPtrAR(@grk, 'Wangi_Prefs_Port'));
  989.                             if port <> NIL then begin
  990.                                 PutMsg(port, pMessage(ipcmsg));
  991.                                 { Wangiprefs will free the memory } 
  992.                                 Permit;
  993.                             End else begin
  994.                                 Permit;
  995.                                 FreeVec(ipcmsg);
  996.                             End;
  997.                         End;
  998.                     End;
  999.                 End;
  1000.                 
  1001.                 ipcmsg := pIPCMsg(GetMsg(WangiPort));
  1002.             End;
  1003.         End;
  1004.         
  1005.         if ((sigre and CxMask)=CxMask) then begin
  1006.             CxMsg := pCxMsg(GetMsg(CxPort));
  1007.             While CxMsg <> NIL do begin
  1008.                 cxtype := CxMsgType(CxMsg);
  1009.                 cxid := pMyNode(CxMsgID(CxMsg));
  1010.                 ReplyMsg(pMessage(CxMsg));
  1011.                 Case cxtype of
  1012.                     CXM_COMMAND : begin
  1013.                         case LONG(cxid) of       { messages from exchange }
  1014.                             CXCMD_DISABLE   : prev := ActivateCxObj(broker,0);
  1015.                             CXCMD_ENABLE    : prev := ActivateCxObj(broker,1);
  1016.                             CXCMD_APPEAR    : OpenUpWindow(w, winmask, appmask);
  1017.                             CXCMD_DISAPPEAR : HideWindow(w, winmask, appmask);
  1018.                             CXCMD_KILL      : ExitFlag := True; 
  1019.                         end;
  1020.                     end;
  1021.                     CXM_IEVENT : Begin
  1022.                         If LONG(cxid) = -1 then begin
  1023.                             { hotkey pressed, show/hide window }
  1024.                             If w = NIL then
  1025.                                 OpenUpWindow(w, winmask, appmask)
  1026.                             else
  1027.                                 HideWindow(w, winmask, appmask);
  1028.                         End else if LONG(cxid) <> 0 then begin
  1029.                             ordn := 0;
  1030.                             nde := CurrentList^.lh_Head;
  1031.                             While (nde^.ln_Succ <> NIL) and (nde <> pNode(cxid)) do begin
  1032.                                 ordn := ordn + 1;
  1033.                                 nde := nde^.ln_Succ;
  1034.                             End;
  1035.                             
  1036.                             If w <> NIL then begin
  1037.                                 { Highlight node }
  1038.                                 t[0] := GTLV_Selected;
  1039.                                 t[1] := Ordn;
  1040.                                 t[2] := GTLV_MakeVisible;
  1041.                                 t[3] := Ordn;
  1042.                                 If GadToolsBase^.lib_Version < 39 then
  1043.                                     t[4] := GTLV_Top
  1044.                                 else
  1045.                                     t[4] := TAG_IGNORE;
  1046.                                 t[5] := Ordn;
  1047.                                 t[6] := TAG_END;
  1048.                                 GT_SetGadgetAttrsA(G[G_LV], w, NIL, @t);
  1049.                             End;
  1050.                             
  1051.                             { start prog }
  1052.                             Case cxid^.wi_Type of
  1053.                                 TYPE_SHELL : If NOT StartCLIProgram(cxid, NIL) then
  1054.                                     TellError(ERROR_SHELL);
  1055.                                 TYPE_WB : If NOT StartWBProgram(cxid, NIL) then
  1056.                                     TellError(ERROR_WB);
  1057.                                 TYPE_AREXX : SendARexxCommand(PtrToPas(cxid^.wi_RexxCmd),
  1058.                                                       PtrToPas(cxid^.wi_RexxPort),NIL); 
  1059.                             End;
  1060.                         End;
  1061.                     End;
  1062.                 end;
  1063.                 CxMsg := pCxMsg(GetMsg(CxPort));
  1064.             end;
  1065.         End;
  1066.         
  1067.         if ((sigre and NotifyMask)=NotifyMask) then begin
  1068.             NotifyMsg := pNotifyMessage(GetMsg(NotifyPort));
  1069.             While NotifyMsg <> NIL do begin
  1070.                 If notifymsg^.nm_NReq^.nr_UserData = 337 then begin
  1071.                     { the prefs file has been changed, update }
  1072.                     HideWindow(w, winmask, appmask);
  1073.                     CloseFont(CD.cd_TFont);
  1074.                     FreeWBMenus;
  1075.                     FreeRemember(@prk, True);
  1076.                     prk := NIL;
  1077.                     if ReadConfigFile(V.arg_From,LM_LOAD, prk) then begin
  1078.                         RemoveCx;
  1079.                         OpenUpWindow(w, winmask, appmask);
  1080.                         If InitCx then
  1081.                             CxMask := BitMask(CxPort^.MP_SIGBIT);
  1082.                         If InitWBMenus then
  1083.                             WBMMask := BitMask(WBMPort^.MP_SIGBIT);
  1084.                     End;
  1085.                 End;
  1086.             
  1087.                 ReplyMsg(pMessage(notifymsg));
  1088.                 NotifyMsg := pNotifyMessage(GetMsg(NotifyPort));
  1089.             End;
  1090.         End;
  1091.                 
  1092.         
  1093.     End; {while}
  1094. end;